package com.mk.wardsystemserver.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mk.wardsystemserver.pojo.Employee;
import com.mk.wardsystemserver.pojo.Patient;
import com.mk.wardsystemserver.mapper.PatientMapper;
import com.mk.wardsystemserver.pojo.RespBean;
import com.mk.wardsystemserver.pojo.RespPageBean;
import com.mk.wardsystemserver.service.IPatientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-03-24
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements IPatientService {
    @Autowired
    private PatientMapper patientMapper;

    /**
     * 查询病人信息(分页)
     * @param pageCurrent
     * @param pageSize
     * @param patient
     * @return
     */
    @Override
    public RespPageBean getPatientByPage(Integer pageCurrent, Integer pageSize, Patient patient ) {
        //开启分页
        Page<Employee> page = new Page<>(pageCurrent, pageSize);
        IPage<Employee> patientByPage = patientMapper.getPatientByPage(page, patient);
        RespPageBean respPageBean = new RespPageBean(patientByPage.getTotal(), patientByPage.getRecords());
        return respPageBean;
    }


    /**
     *添加病人信息
     * @param patient
     * @return
     */
    @Override
    public RespBean addPatient(Patient patient) {
        if(1==patientMapper.insert(patient)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    /**
     * 获取费用明细
     * @return
     */
    @Override
    public List<Patient> getPayDetails() {
        return patientMapper.getPayDetails();
    }

    /**
     * 病人治疗信息查询
     * @return
     */
    @Override
    public RespPageBean getInfo(Integer pageCurrent, Integer pageSize, Patient patient) {
        Page<Patient> page=new Page<>(pageCurrent,pageSize);
        IPage<Patient> payInfo=patientMapper.getInfo(page,patient);
        RespPageBean respPageBean=new RespPageBean(payInfo.getTotal(),payInfo.getRecords());
        return respPageBean;
    }

}
